    <div class="head"><h5 class="iList">Directory</h5></div>
     <form action="<?php echo url_for('directories/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" id="valid" class="mainForm" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
     	<div class="rowElem noborder">
     	<label for="name">Name:</label>
     		<div class="formRight"><input type="text" name="master_directory[name]" value="<?php echo $form->getObject()->getName()?>"  class="validate[required]"  id="master_directory_name"/></div>
     		<div class="fix"></div>
     	</div>
     	
     	<div class="rowElem noborder">
     	<label for="name">Domain:</label>

     		
     		<?php if ($form->getObject()->getParentId() != null) {?>     	
     	    <div  style="  float: left;font-style: italic;line-height: 0;margin-left: 109px; margin-top: 15px;text-align: right;">
     	     <?php echo $form->getObject()->getParent()->getDomain() ?>
     		</div>
			<?php }?>
			
     		<div class="formRight" >
     		<input style="width:528px;" type="text" name="master_directory[domain]" value="<?php echo $form->getObject()->getDomain()?>"  class="validate[required]"  id="master_directory_domain"  />
     		</div>			
			
     		<div class="fix"></div>
     	</div>
     	
     	<div class="rowElem noborder">
	     	<label for="name">Language:</label>
     		<div class="formRight" >
                    			<select name="master_directory[language_id]" id="master_directory_language_id" style="width:240px;" >
                    				<option value="">--Select--</option>
                    				<?php 
                    					
                    					foreach ($languages as $language) {
		                    					 $language_selected = $language->getId() == $form->getObject()->getLanguageId() ? "selected" : "";
		                    					?>
		                    						<option <?php echo $language_selected?> value="<?php echo $language->getId(); ?>"><?php echo $language->getName(); ?></option>
		                    					<?php 
                    					}
                    				?>
                            	</select>     		
     		
     		</div>
     		<div class="fix"></div>
     	</div>     	
     	
     	<div class="rowElem noborder">
     	<label for="name">Facebook App Id:</label>
     		<div class="formRight"><input type="text" name="master_directory[fb_app]" value="<?php echo $form->getObject()->getFbApp()?>"  id="master_directory_fb_app"/></div>
     		<div class="fix"></div>
     	</div>     	
     	
     	<div class="rowElem noborder">
	     	<label for="name">Color:</label>
     		<div class="formRight" >
                <div style="float:left;">    
                	<?php $color = ($form->getObject()->getThemeColor() != null && $form->getObject()->getThemeColor() != '') ? $form->getObject()->getThemeColor() : '#90cd67'?>			
                	<input style="width:50px; background-color: <?php echo $color?>" type="text" name="master_directory[theme_color]" value="<?php echo $color ?>"  class="validate[required]"  id="master_directory_theme_color"/>
                </div>
                <div style="float:left;">    			
					<div id="stlChanger" style="position: relative; top:-1px;left: 15px;width: 120px;">
								<div class="blockChanger bgChanger" style="left: 0px;">
									<!-- <a class="chBut" href="#">&nbsp;</a> -->
									<div class="chBody" style="display: block;">
										<div class="stBlock">
											<span>pick color</span>
											<div class="stColorParent">
												<a class="stColor2" href="#"><span style="background-color: rgb(245, 0, 0);" title="90cd67" id="cFontWColor1">&nbsp;</span></a>
											</div>
										</div>
										<div class="stBlock">
											<span>use preset</span>
											<div class="hdrStBgs">
												<div class="hdrCols">
													<span title="90cd67" style="background-color:#90cd67;" class="current">&nbsp;</span>
													<span title="9e86ae" style="background-color:#9e86ae;">&nbsp;</span>
													<span title="2fd2ea" style="background-color:#2fd2ea;">&nbsp;</span>
													<span title="ff6b39" style="background-color:#ff6b39;">&nbsp;</span>
													<span title="e1565c" style="background-color:#e1565c;">&nbsp;</span>
													<span title="ff3973" style="background-color:#ff3973;">&nbsp;</span>
													<div class="cl"></div>
												</div>
											</div>
										</div>
									</div>
								</div>
					</div>
				</div>                    			
                    			     		
     		
     		</div>
     		<div class="fix"></div>
     	</div>     	
     	
     	<div class="rowElem noborder" id="google_analytics">
	     	<label for="directory_type">Google Analytics Script:</label>
     		<div class="formRight" >
                    			<textarea rows="" cols="" name="master_directory[analytics_script]" id="master_directory_analytics_script"><?php 
                    				$script = $form->getObject()->getAnalyticsScript() != null ? $form->getObject()->getAnalyticsScript() : "";
                    				echo $script;
                    				?></textarea>    		
     		
     		</div>
     		<div class="fix"></div>
     	</div>
     	
     	<div class="rowElem noborder" style="display: none;">
	     	<label for="directory_type">Directory Type:</label>
     		<div class="formRight" >
                    			<select name="master_directory[directory_type_id]" id="master_directory_directory_type_id" style="width:240px;" onchange="manageAnalitycsVisibility()" >
                    				<?php 
                    					foreach ($directories_types as $directory_type) {
                    						
                    					 $selected = $directory_type->getId() == $form->getObject()->getDirectoryTypeId() ? "selected" : "";
                    					?>
                    						<option <?php echo $selected?> value="<?php echo $directory_type->getId(); ?>"><?php echo $directory_type->getName(); ?></option>
                    					<?php 
                    					}
                    				?>
                            	</select>     		
     		
     		</div>
     		<div class="fix"></div>
     	</div>     	

     	<div class="rowElem noborder">
	     	<label for="directory_type">Currency symbol:</label>
     		<div class="formRight" >
                   <input type="text" name="master_directory[currency_symbol]" style="width:200px" value="<?php echo $form->getObject()->getCurrencySymbol()?>"  id="master_directory_currency_symbol"/>	  		
     		
     		</div>
     		<div class="fix"></div>
     	</div>     	
     	
     	<div class="rowElem noborder">
	     	<label for="directory_type">Variable a (for travel price formula):</label>
     		<div class="formRight" >
                   <input type="text" name="master_directory[price_formula_a]" style="width:200px" value="<?php echo $form->getObject()->getPriceFormulaA()?>"  id="master_directory_price_formula_a"/>	  		
     		
     		</div>
     		<div class="fix"></div>
     	</div>     	

     	<div class="rowElem noborder" >
	     	<label for="directory_type">Variable b (for travel price formula):</label>
     		<div class="formRight" >
                   <input type="text" name="master_directory[price_formula_b]" style="width:200px" value="<?php echo $form->getObject()->getPriceFormulaB()?>"  id="master_directory_price_formula_b"/>	  		
     		</div>
     		<div class="fix"></div>
     	</div>     	
     	
     	<div class="rowElem noborder" >
	     	<label for="directory_type">Google site verificatioin code</label>
     		<div class="formRight" >
                   <input type="text" name="master_directory[google_site_verification]" value="<?php echo $form->getObject()->getGoogleSiteVerification()?>"  id="master_directory_google_site_verification"/>	  		
     		</div>
     		<div class="fix"></div>
     	</div>          	
     	
     	
     	<div class="rowElem noborder" style="display: none">
	     	<label for="name">Parent:</label>
     		<div class="formRight" >
                    			<select name="master_directory[parent_id]" id="master_directory_parent_id" style="width:240px;"  onchange="manageAnalitycsVisibility()">
                    				<option value="">--Select--</option>
                    				<?php 
                    					
                    					foreach ($master_directories as $directory) {
                    						if($directory->getId() != $form->getObject()->getId()){
		                    					 $selected = $directory->getId() == $form->getObject()->getParentId() ? "selected" : "";
		                    					?>
		                    						<option <?php echo $selected?> value="<?php echo $directory->getId(); ?>"><?php echo $directory->getName(); ?></option>
		                    					<?php 
		                    				}
                    					}
                    				?>
                            	</select>     		
     		
     		</div>
     		<div class="fix"></div>
     	</div>
     	     	
     	<div class="fix"></div>
     	<?php if ($sf_user->getAttribute('rol_id') == sfConfig::get('app_admin') || !$form->getObject()->isNew()){
     		?>
        <input type="button" value="Save" class="greyishBtn submitForm" id="save" />

     	<?php 
     	} ?>        
        <div class="fix"></div>
        <input type="hidden" name="master_directory[home_template_id]" value=<?php echo $form->getObject()->getHomeTemplateId()?>>
        
        <input type="hidden" name="master_directory[user_id]" value=<?php echo $sf_user->getAttribute('user_id');?>>
        
        <input type="hidden" name="master_directory[search_button_caption]" value=<?php echo $form->getObject()->getSearchButtonCaption()?>>
        
        <input type="hidden" name="master_directory[search_title]" value=<?php echo $form->getObject()->getSearchTitle()?>>
     </form>
     
 
<script type="text/javascript">

$("#save").click(function (event){
    submitForm();
})

$("form#valid").submit(function (event){
    event.preventDefault();
    submitForm();
})

$("#create_new").click(function (event){

    $.ajax({type: 'POST', url:' <?php echo url_for('directories/index')?>', script:true, cache:false,
            success: function(data) {
                 $('#directory_container_div').html(data);
                 $('#template_name').attr('value',"");
             } });
             
})

function manageAnalitycsVisibility(){
	var selectedIndex = $('option:selected', '#master_directory_parent_id').index();
	if(selectedIndex > 0){
		$('#master_directory_analytics_script').attr('value', '');
		$('#google_analytics').hide();
	}else{
		$('#google_analytics').show();
	}
}

function submitForm(){
    var str=$('form#valid').serialize();

    $.ajax({type: 'POST', url:' <?php echo url_for('directories/'.($form->getObject()->isNew() ? 'create' :'update').
    (!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : ''))?>', script:true, cache:false, data:  str, 
    beforeSend: function(){
				    	if (!validate()){
							return false;
				        }
						},
            success: function(data) {
                 $('#directory_container_div').html(data);
                 $('#master_directory_name').attr('value',"");
             } });
}


function validate(){
	var valid = true;
	var error_msg = "";
	if ($("#master_directory_name").attr("value") == ""){
		valid = false;
		error_msg = "Name required";
	}
	else if(valid && $("#master_directory_domain").attr("value") == ""){
		valid = false;
		error_msg = "Domain required";
	}	
	else if(valid && $('option:selected', '#master_directory_language_id').index() == 0){
		valid = false;
		error_msg = "Language required";
	}	
		
	if (!valid){
		$('#msg_text').html(error_msg);
		$('#error_msg').show('fast');
	}
	return valid;			
}


		$('form').jqTransform({imgPath:'../images/forms'});

		$('#stlChanger').ColorPicker();
		
		jQuery('#stlChanger .hdrStBgs .hdrCols span').click(function(){
			
			var hdrCol = jQuery(this).attr('title');
			
			
			
			jQuery('#stlChanger .hdrStBgs .hdrCols span').removeClass('current');
			jQuery(this).addClass('current');
			
			jQuery('#stlChanger').find('#cFontWColor1').css({backgroundColor:'#' + hdrCol});
			
			jQuery('#master_directory_theme_color').attr('value', '#' + hdrCol);

			jQuery('#master_directory_theme_color').css('background-color', '#' + hdrCol);

			
			
				jQuery('#cFontStyleWColor1').text('a, .color_3, q:before, blockquote:before, .blog .post h2.entry-title a:hover, .portfolio_container .portfolio .entry-title a:hover, ul.p_filter li.current a, ul.p_filter li a:hover, .blog.short .post .entry-title a:hover, h5 {color:#' + hdrCol + ';}');
				
				
				
				jQuery('#cFontStyleWColor2').text('code:before, span.dropcap2, .table thead th, .colored_block, #navigation li.current_page_item > a, #navigation li:hover > a:hover, #navigation ul li:hover > a, .post .published, .shortcode_slideshow ul.shortcode_slideshow_pager li.current a, .shortcode_slideshow ul.shortcode_slideshow_pager li a:hover, .wp-pagenavi a, .cmsmsLike:hover, .cmsmsLike.active, .button, .button_medium, .button_large, .logo img {background-color:#' + hdrCol + ';}');
				jQuery('#cFontStyleWColor3').text('input[type="text"]:focus, textarea:focus, #bottom input[type="text"]:focus, #bottom textarea:focus, .cmsmsLike:hover {border-color:#' + hdrCol + ';}');
				jQuery('#cFontStyleWColor4').text('#header, #navigation > li > ul > li:first-child > a {border-top-color:#' + hdrCol + ';}');
				jQuery('#cFontStyleWColor5').text('#navigation ul li.current_page_item:first-child > a:before, #navigation ul li:first-child > a:hover:before, #navigation ul li.current_page_item:first-child:hover > a:hover:before, #navigation ul li:first-child > a:before	{border-bottom-color:#' + hdrCol + ';}');
			return false;
		});
		
		/* Color Scheme */
		jQuery('#stlChanger #cFontWColor1').parent('a').ColorPicker({
			onChange:function(hsb, hex, rgb){
				//$("a").css("color", "#" + hex);
				jQuery('#stlChanger').find('#cFontWColor1').css({backgroundColor:'#' + hex});
				jQuery('#cFontStyleWColor1').text('a, .color_3, q:before, blockquote:before, .blog .post h2.entry-title a:hover, .portfolio_container .portfolio .entry-title a:hover, ul.p_filter li.current a, ul.p_filter li a:hover, .blog.short .post .entry-title a:hover, h5 {color:#' + hex + ';}');
				jQuery('#cFontStyleWColor2').text('code:before, span.dropcap2, .table thead th, .colored_block, #navigation li.current_page_item > a, #navigation li:hover > a:hover, #navigation ul li:hover > a, .post .published, .shortcode_slideshow ul.shortcode_slideshow_pager li.current a, .shortcode_slideshow ul.shortcode_slideshow_pager li a:hover, .wp-pagenavi a, .cmsmsLike:hover, .cmsmsLike.active, .button, .button_medium, .button_large, .logo img {background-color:#' + hex + ';}');
				jQuery('#cFontStyleWColor3').text('input[type="text"]:focus, textarea:focus, #bottom input[type="text"]:focus, #bottom textarea:focus, .cmsmsLike:hover {border-color:#' + hex + ';}');
				jQuery('#cFontStyleWColor4').text('#header, #navigation > li > ul > li:first-child > a {border-top-color:#' + hex + ';}');
				jQuery('#cFontStyleWColor5').text('#navigation ul li.current_page_item:first-child > a:before, #navigation ul li:first-child > a:hover:before, #navigation ul li.current_page_item:first-child:hover > a:hover:before, #navigation ul li:first-child > a:before {border-bottom-color:#' + hex + ';}');
				
				jQuery('#master_directory_theme_color').attr('value', '#' + hex);

				jQuery('#master_directory_theme_color').css('background-color', '#' + hex);
			},
			onSubmit:function(hsb, hex, rgb, el){
				//$("a").css("color", "#" + hex);
				jQuery('#cFontStyleWColor1').text('a, .color_3, q:before, blockquote:before, .blog .post h2.entry-title a:hover, .portfolio_container .portfolio .entry-title a:hover, ul.p_filter li.current a, ul.p_filter li a:hover, .blog.short .post .entry-title a:hover, h5 {color:#' + hex + ';}');
				jQuery('#cFontStyleWColor2').text('code:before, span.dropcap2, .table thead th, .colored_block, #navigation li.current_page_item > a, #navigation li:hover > a:hover, #navigation ul li:hover > a, .post .published, .shortcode_slideshow ul.shortcode_slideshow_pager li.current a, .shortcode_slideshow ul.shortcode_slideshow_pager li a:hover, .wp-pagenavi a, .cmsmsLike:hover, .cmsmsLike.active, .button, .button_medium, .button_large, .logo img {background-color:#' + hex + ';}');
				jQuery('#cFontStyleWColor3').text('input[type="text"]:focus, textarea:focus, #bottom input[type="text"]:focus, #bottom textarea:focus, .cmsmsLike:hover {border-color:#' + hex + ';}');
				jQuery('#cFontStyleWColor4').text('#header, #navigation > li > ul > li:first-child > a {border-top-color:#' + hex + ';}');
				jQuery('#cFontStyleWColor5').text('#navigation ul li.current_page_item:first-child > a:before, #navigation ul li:first-child > a:hover:before, #navigation ul li.current_page_item:first-child:hover > a:hover:before, #navigation ul li:first-child > a:before {border-bottom-color:#' + hex + ';}');
				jQuery(el).find('#cFontWColor1').css({backgroundColor:'#' + hex});
				jQuery(el).find('#cFontWColor1').attr({title:hex});
				jQuery(el).ColorPickerHide();
				jQuery('#master_directory_theme_color').attr('value', '#' + hex);
				jQuery('#master_directory_theme_color').css('background-color', '#' + hex);
			},
			onBeforeShow:function(){
				jQuery(this).ColorPickerSetColor(jQuery('#stlChanger').find('#cFontWColor1').attr('title'));
			}
		});

		
		//if (jQuery(window).height() < 750){ jQuery('#stlChanger').css({position:'absolute'}); }

		
		/* Style Changer Autohide */
		/*jQuery('.chBut').parent().delay(1000).animate({left:'-120px'}, 500, function(){
			jQuery(this).find('.chBut').next('.chBody').css({display:'none'});
			jQuery(this).find('.chBut').addClass('closed');
		}); */
		
		
		/* Style Changer Toggle */
		jQuery('.chBut').click(function(){
			if (jQuery(this).hasClass('closed')){
				jQuery(this).next('.chBody').css({display:'block'}).parent().animate({left:0}, 500, function(){
					jQuery(this).find('.chBut').removeClass('closed');
				});
			} else {
				jQuery(this).parent().animate({left:'-120px'}, 500, function(){
					jQuery(this).find('.chBut').next('.chBody').css({display:'none'});
					jQuery(this).find('.chBut').addClass('closed');
				});
			}
			
			return false;
		});


	
		
</script>     
